package com.leyou.auth.config;

import com.leyou.common.auth.utils.RsaUtils;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.security.PrivateKey;
import java.security.PublicKey;

@Data
@Component
@ConfigurationProperties(prefix = "ly.jwt")
public class JwtProperties{

    private String pubKeyPath;
    private String priKeyPath;
    private CookiePojo cookie = new CookiePojo();
    private AppPojo app = new AppPojo();

    //获取公钥和私有对象
    private PublicKey publicKey;
    private PrivateKey privateKey;

    // 该注解的方法在整个Bean初始化中的执行顺序：
    // Constructor(构造方法) -> @Autowired(依赖注入) -> @PostConstruct(注释的方法)
    @PostConstruct
    public void initMethod() throws Exception {
        publicKey = RsaUtils.getPublicKey(pubKeyPath);
        privateKey = RsaUtils.getPrivateKey(priKeyPath);
    }

    @Data
    public class CookiePojo{
        private Integer expire;
        private Integer refreshTime;
        private String cookieName;
        private String cookieDomain;
    }

    @Data
    public class AppPojo{
        private Integer expire;//过期时间
    }
}
